#include<stdio.h>

int maxProfit(int prices[], int n) {   		 
        if (n < 2) return 0;

        int maxProfit = 0;
        int curMin = prices[0];
        int i;
        for ( i = 1; i < n; i++) {   		 
            curMin = (curMin < prices[i] ) ? curMin : prices[i];
            maxProfit =  (maxProfit >  prices[i] - curMin )? maxProfit : (prices[i] - curMin) ;
        }

        return maxProfit;
 }

int main(int argc, char **argv)
{   		 
    int  array[128];
    int n,i;
    printf("Please input the array size\n");
    scanf("%d",&n);
    for(i=0; i < n; i++)
    {   		 
        printf("Please input the %d-th number\n",i);
        scanf("%d",&array[i]);
    }
    int sum = maxProfit(array, n);
    printf("the maxProfit is %d\n",sum );

}